package com.novacloud.redis;

import com.novacloud.dto.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author <a href="mailto:huzhanjun@novacloud.com">huzj</a>
 * @version 1.0
 * @date 2017/9/21 14:03
 */
@Repository
public class PersonService {

    @Autowired
    RedisTemplate<Object, Object> redisTemplate;

    @Resource(name = "redisTemplate")
    ValueOperations<Object, Object> valueOperations;
    public void save(Person person) {
        valueOperations.set(person.getId(), person);
    }

    public Person get(String id) {
        return (Person)valueOperations.get(id);
    }

    public void delete(String id) {
        redisTemplate.delete(id);
    }
}
